<script type="text/javascript" th:src="@{#{webjars.zxcvbn.js}}"></script>
<script type="text/javascript" th:src="@{#{webjars.jqueryui.js}}"></script>
<script type="text/javascript" th:src="@{#{webjars.jquerycookie.js}}"></script>
<script src="//www.google.com/recaptcha/api.js" async defer th:if="${recaptchaSiteKey != null and recaptchaVersion=='v2'}"></script>
<script th:src="${'//www.google.com/recaptcha/api.js?render=' + recaptchaSiteKey}" th:if="${recaptchaSiteKey != null and recaptchaVersion == 'v3'}"></script>
<script th:src="@{#{webjars.bootstrapmin.js}}"></script>

<script th:src="@{#{webjars.headmin.js}}"></script>
<script type="text/javascript" th:src="@{${#themes.code('cas.javascript.file')}}"></script>

<script th:inline="javascript">
    head.ready(document, function () {
        if (!window.jQuery) {
            var jqueryUrl = /*[[@{#{webjars.jquerymin.js}}]]*/;
            head.load(jqueryUrl, loadjQueryUI);
        } else {
            notifyResourcesAreLoaded(resourceLoadedSuccessfully);
        }
    });

    function loadjQueryUI() {
        var jqueryUrl = /*[[@{#{webjars.jqueryui.js}}]]*/;
        head.load(jqueryUrl, loadjQueryCookies);
    }

    function loadjQueryCookies() {
        var jqueryUrl = /*[[@{#{webjars.jquerycookie.js}}]]*/;
        head.load(jqueryUrl, notifyResourcesAreLoaded(resourceLoadedSuccessfully));
    }

    function notifyResourcesAreLoaded(callback) {
        if (typeof callback === "function") {
            callback();
        }
    }
</script>

<script th:inline="javascript">
    /*<![CDATA[*/

    var trackGeoLocation = /*[[${trackGeoLocation}]]*/ ===
    "true";

    var googleAnalyticsTrackingId = /*[[${googleAnalyticsTrackingId}]]*/;

    if (googleAnalyticsTrackingId != null && googleAnalyticsTrackingId != '') {
        (function (i, s, o, g, r, a, m) {
            i['GoogleAnalyticsObject'] = r;
            i[r] = i[r] || function () {
                (i[r].q = i[r].q || []).push(arguments)
            }, i[r].l = 1 * new Date();
            a = s.createElement(o),
                m = s.getElementsByTagName(o)[0];
            a.async = 1;
            a.src = g;
            m.parentNode.insertBefore(a, m)
        })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');

        ga('create', googleAnalyticsTrackingId, 'auto');
        ga('send', 'pageview');
    }

    /*]]>*/
</script>

<span th:if="${recaptchaVersion=='v2'}" th:remove="tag">
    <script type="text/javascript" th:if="${recaptchaSiteKey != null AND recaptchaInvisible != null AND recaptchaInvisible}" th:inline="javascript">
        function onRecaptchaV2Submit(token) {
            $('#fm1').submit();
        }
    </script>
</span>

<span th:if="${recaptchaVersion=='v3'}" th:remove="tag">
    <script type="text/javascript" th:if="${recaptchaSiteKey != null}" th:inline="javascript">
         grecaptcha.ready(function() {
             grecaptcha.execute(/*[[${recaptchaSiteKey}]]*/, {action: 'login'})
                 .then(function(token) {
                    $("#g-recaptcha-token").val(token)
                 });
         });
    </script>
</span>
